package com.tesis_2.UI;

import java.util.ArrayList;

import org.json.JSONException;

import com.example.t2_clientback.R;
import com.tesis_2.BL.BLPlatos;

import com.tesis_2.MO.MOPlato;
import com.tesis_2.Utils.UTPLatosAdapter;


import android.os.Bundle;

import android.app.ListActivity;
import android.content.Intent;

import android.view.Menu;
import android.view.MenuItem;


public class UIPlatos extends ListActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		//setContentView(R.layout.activity_uiplatos);
		// Show the Up button in the action bar.
		//getActionBar().setDisplayHomeAsUpEnabled(true);
		
		ArrayList<MOPlato> lsPlatos = new ArrayList<MOPlato>();
		
		try {
			BLPlatos.fillPlatos();
			lsPlatos = BLPlatos.getLsPlatos();
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		try {
			setListAdapter( new UTPLatosAdapter(this, lsPlatos));
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_uiplatos, menu);
		return true;
	}


	public boolean onOptionsItemSelected(MenuItem item) {
	    
		Intent intent; 
		
		switch (item.getItemId()) 
	    {
	        case R.id.optAgregar_plato:
	        	intent = new Intent(this, UISeleccionarRestLocal.class);
				intent.putExtra("modo", 2);
				startActivity(intent);
	        break;
	        
	        default: 
	        	
	        break;
	    }
	    return false;
	} 

}
